<template>
  <div class="p-2">
    <transition :enter-active-class="proxy?.animate.searchAnimate.enter" :leave-active-class="proxy?.animate.searchAnimate.leave">
      <div v-show="showSearch" class="mb-[10px]">
        <!-- <el-card shadow="hover">
          <el-form ref="queryFormRef" :model="queryParams" :inline="true">
            <el-form-item label="报告ID" prop="reportId">
              <el-input v-model="queryParams.reportId" placeholder="请输入报告ID" clearable @keyup.enter="handleQuery" />
            </el-form-item>
            <el-form-item label="领域" prop="field">
              <el-input v-model="queryParams.field" placeholder="请输入领域" clearable @keyup.enter="handleQuery" />
            </el-form-item>
            <el-form-item>
              <el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
              <el-button icon="Refresh" @click="resetQuery">重置</el-button>
            </el-form-item>
          </el-form>
        </el-card> -->
      </div>
    </transition>

    <el-card shadow="never">
      <template #header>
        <el-row :gutter="10" class="mb8">
          <el-col :span="1.5"> </el-col>
          <right-toolbar v-model:showSearch="showSearch" :search="false" @queryTable="getList"></right-toolbar>
        </el-row>
      </template>

      <el-table v-loading="loading" border :data="dissentList">
        <el-table-column label="主体名称" prop="ztName" min-width="150px" />
        <el-table-column label="统一代码" prop="ztCode" width="190px" />
        <el-table-column label="报告编号" prop="reportNo" width="200px" />
        <el-table-column label="领域" prop="field" min-width="150px" show-overflow-tooltip />
        <el-table-column label="问题说明" prop="userRemark" min-width="150px" />
        <el-table-column label="状态" align="center" prop="status" width="80px">
          <template #default="{ row }">
            <dict-tag :options="xydz_dissent_status" :value="row.status" />
          </template>
        </el-table-column>
        <el-table-column label="操作" align="center" fixed="right" width="120px">
          <template #default="{ row }">
            <el-tooltip content="预览报告" placement="top">
              <el-button link type="primary" icon="View" @click="previewReport(row)"></el-button>
            </el-tooltip>
            <el-tooltip content="下载报告" placement="top">
              <el-button link type="primary" icon="Download" @click="downloadReport(row)"></el-button>
            </el-tooltip>
            <el-tooltip :content="row.status == '0' || row.status == '1' ? '办理' : '查看详情'" placement="top">
              <el-button
                link
                type="primary"
                :icon="row.status == '0' || row.status == '1' ? 'Position' : 'Document'"
                @click="handleRow(row)"
              ></el-button>
            </el-tooltip>
          </template>
        </el-table-column>
      </el-table>

      <pagination v-show="total > 0" :total="total" v-model:page="queryParams.pageNum" v-model:limit="queryParams.pageSize" @pagination="getList" />
    </el-card>
    <handleDialog @updateList="getList" ref="handleDialogRef"></handleDialog>
  </div>
</template>

<script setup name="Dissent" lang="ts">
import { listDissent } from '@/api/xydz/dissent/index';
import { DissentVO } from '@/api/xydz/dissent/types';
import handleDialog from './handle-dialog.vue';

const { proxy } = getCurrentInstance() as ComponentInternalInstance;
const { xydz_dissent_status } = toRefs<any>(proxy?.useDict('xydz_dissent_status'));

const dissentList = ref<DissentVO[]>([]);
const loading = ref(true);
const showSearch = ref(false);
const total = ref(0);

const queryFormRef = ref<ElFormInstance>();
const handleDialogRef = ref<InstanceType<typeof handleDialog>>();

const state = reactive({
  queryParams: {
    pageNum: 1,
    pageSize: 10
    // reportId: '',
    // field: ''
  }
});

const { queryParams } = toRefs(state);

onMounted(() => {
  getList();
});

/** 搜索按钮操作 */
const handleQuery = () => {
  queryParams.value.pageNum = 1;
  getList();
};

/** 重置按钮操作 */
const resetQuery = () => {
  queryFormRef.value?.resetFields();
  handleQuery();
};

/** 查询异议信息列表 */
const getList = async () => {
  loading.value = true;
  const res = await listDissent(queryParams.value);
  dissentList.value = res.rows;
  total.value = res.total;
  loading.value = false;
};

//办理
const handleRow = (row: DissentVO) => {
  handleDialogRef.value.show(row);
};

//预览报告
const previewReport = (row: DissentVO) => {
  proxy?.$preview.report(row.reportId);
};

//下载报告
const downloadReport = (row: DissentVO) => {
  proxy?.$download.report(row.reportId);
};
</script>

<style lang="scss" scoped>
.evidence {
  color: #409eff;
}
</style>
